var map;
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var global_markers = [];

var infowindow = new google.maps.InfoWindow({});

function initialize() {
	directionsDisplay = new google.maps.DirectionsRenderer({suppressMarkers:true});
	geocoder = new google.maps.Geocoder();
	var latlng = new google.maps.LatLng(markers[1][0], markers[1][1]);
	
	var myOptions = {
		zoom: 11,
		center: latlng,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	}
	
	map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

	directionsDisplay.setMap(map);
	
	addMarker();
}

function addMarker() {
	for (var i = 0; i < markers.length; i++) {
		// obtain the attribues of each marker
		var lat = parseFloat(markers[i][0]);
		var lng = parseFloat(markers[i][1]);
		var trailhead_name = markers[i][2];
		
		var myLatlng = new google.maps.LatLng(lat, lng); 

		var contentString = "<html><body>" + trailhead_name + "</body></html>";
		
		if(i==1){
			var icon_img = BASEURL + "img/misc/hotel-map-icon.png";
		} else {
			var icon_img = BASEURL + "img/misc/airport-map-icon.png";
		}
		
		var marker = new google.maps.Marker({
			position: myLatlng,
			map: map,
			icon: icon_img,
			title: "Coordinates: " + lat + " , " + lng
		});

		marker['infowindow'] = contentString;

		global_markers[i] = marker;

		google.maps.event.addListener(global_markers[i], 'click', function() {
			infowindow.setContent(this['infowindow']);
			infowindow.open(map, this);
		});
	}
}

window.onload = initialize;